package com.code.day03;

import com.code.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo04JDBC {

    public static void main(String[] args) throws SQLException {
        Scanner sc=new Scanner(System.in);
        System.out.println("输入用户名:");
        String usr = sc.nextLine();
        System.out.println("输入用户密码:");
        String pwd = sc.nextLine();

        Connection conn= JDBCUtils.getConnection();
        String sql="select password from `t_user` where username=? ";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setObject(1,usr);
        ResultSet rs=pstmt.executeQuery();

        if(rs.next()){
            System.out.println("登录成功");
        }else{
            System.out.println("登录失败");
        }

        JDBCUtils.closeConnection(conn,pstmt,rs);





    }
}
